﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using aspProject.Dmain.Domain;
using System.Data.Entity;

namespace aspProject.Dmain.DAL
{
     public class LabelTypeRepository : ILabelTypeRepository
    {
        private readonly CentricEntities _context;
        private readonly DbSet<LabelType> _labelTypes;

        public LabelTypeRepository(CentricEntities context)
        {
            this._context = context;
            _labelTypes = context.LabelTypes;
        }


        public IQueryable<LabelType> FindAll()
        {
            return _labelTypes;
        }

        public LabelType FindById(int dataConfigId)
        {
            return _labelTypes.SingleOrDefault(l => l.Id == dataConfigId);
        }


        public IQueryable<Theme> FindAllThemesForType(LabelType type)
        {
            return type.Themes.AsQueryable();
        }

        public IQueryable<Template> FindAllTemplatesForType(LabelType type)
        {
            return type.Templates.AsQueryable();
        }

        public IQueryable<FieldConfig> FindAllFieldConfigsForType(LabelType type)
        {
            return type.FieldConfigs.AsQueryable();
        }

        public IQueryable<DataConfig> FindAllDataConfigsForType(LabelType type)
        {
            return type.DataConfigs.AsQueryable();
        }

        public void AddDataConfig(DataConfig dataConfig)
        {
            _context.DataConfigs.Add(dataConfig);
        }

         public void AddFieldConfig(FieldConfig fieldConfig)
         {
             _context.FieldConfigs.Add(fieldConfig);
         }

         public void AddTemplate(Template template)
         {
             _context.Templates.Add(template);
         }

         public Theme FindThemeById(int id)
         {
             return _context.Themes.FirstOrDefault(t => t.Id == id);
         }
         public Template FindTemplateById(int id)
         {
             return _context.Templates.FirstOrDefault(t => t.Id == id);
         }
         public FieldConfig FindFieldConfigById(int id)
         {
             return _context.FieldConfigs.FirstOrDefault(f => f.Id == id);
         }
         public DataConfig FindDataConfigById(int id)
         {
             return _context.DataConfigs.FirstOrDefault(d => d.Id == id);
         }


        public void SaveChanges()
        {
            _context.SaveChanges();
        }
    }
}
